package ledgerapi

import "github.com/hyperledger/fabric-contract-api-go/contractapi"

type TransactionContextInterface interface {
	contractapi.TransactionContextInterface
	GetStateDb() StateDataDb
	GetRelatedKeyStub() *RelatedKeyStub
}

type TransactionContext struct {
	contractapi.TransactionContext
	stateDb *StateDataLedgerDb
	keyStub *RelatedKeyStub
}

func(ctx *TransactionContext) GetStateDb() StateDataDb {
	if ctx.stateDb == nil {
		ctx.stateDb = &StateDataLedgerDb{
			Ctx: ctx,
		}
	}
	return ctx.stateDb
}
func(ctx *TransactionContext) GetRelatedKeyStub() *RelatedKeyStub {
	if ctx.keyStub == nil {
		ctx.keyStub = &RelatedKeyStub{
			stub: ctx.GetStub(),
		}
	}
	return ctx.keyStub
}
